package jdbc;

import java.sql.*;

/**
 * 使用预编译sql语句
 */
public class JDBCDemo7 {
    public static void main(String[] args) {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(), "欢迎登录", "登录");

        try (Connection connection = DBUtil.getConnection()) {
            String sql="select id, username ,password ,nickname,age " +
                    "from userinfo " +
                    "where username = ? and password = ?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,userInfo.getUsername());
            ps.setString(2,userInfo.getPassword());
            ResultSet resultSet = ps.executeQuery();
            if (resultSet.next()){
                System.out.println("登陆成功");
            }else {
                System.out.println("登陆失败");
            }

        }catch(SQLException e){
            e.printStackTrace();
        }


    }
}
